package com.example.foobar.dao.service.impl;

import com.example.foobar.dto.RetentionRateDTO;
import com.example.foobar.entity.DaQrcodeRetentionRates;
import com.example.foobar.mapper.DaQrcodeRetentionRatesMapper;
import com.example.foobar.dao.service.DaQrcodeRetentionRatesDaoService;
import com.example.foobar.param.DaQrcodeRetentionRatesPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 留存率记录 服务实现类
 *
 * @author 郑英奔
 * @since 2021-07-16
 */
@Slf4j
@Service
public class DaQrcodeRetentionRatesDaoServiceImpl extends BaseServiceImpl<DaQrcodeRetentionRatesMapper, DaQrcodeRetentionRates> implements DaQrcodeRetentionRatesDaoService {

    @Autowired
    private DaQrcodeRetentionRatesMapper daQrcodeRetentionRatesMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveDaQrcodeRetentionRates(DaQrcodeRetentionRates daQrcodeRetentionRates)  {
        return super.save(daQrcodeRetentionRates);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateDaQrcodeRetentionRates(DaQrcodeRetentionRates daQrcodeRetentionRates)  {
        return super.updateById(daQrcodeRetentionRates);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteDaQrcodeRetentionRates(Long id)  {
        return super.removeById(id);
    }

    @Override
    public Paging<DaQrcodeRetentionRates> getDaQrcodeRetentionRatesPageList(DaQrcodeRetentionRatesPageParam daQrcodeRetentionRatesPageParam)  {
        Page<DaQrcodeRetentionRates> page = new PageInfo<>(daQrcodeRetentionRatesPageParam, OrderItem.desc(getLambdaColumn(DaQrcodeRetentionRates::getCreateTime)));
        LambdaQueryWrapper<DaQrcodeRetentionRates> wrapper = new LambdaQueryWrapper<>();
        IPage<DaQrcodeRetentionRates> iPage = daQrcodeRetentionRatesMapper.selectPage(page, wrapper);
        return new Paging<DaQrcodeRetentionRates>(iPage);
    }

    @Override
    public List<RetentionRateDTO> getQrCodeStroyRetentonRates(String sceneId, Date startDate, Date endDate) {
        Map<String, Object> params = new HashMap<>();
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        params.put("sceneId",sceneId);
        List<RetentionRateDTO> list = daQrcodeRetentionRatesMapper.getQrCodeStroyRetentonRates(params);
        return list;
    }

}
